[video_player_avfoundation] fix playback speed resetting #7657
+76
−24
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Calling play is the same as setting the rate to 1.0 (or to
defaultRate
depending on ios version, documentation in this first link is clearly not updated because it does not mentiondefaultRate
):https://developer.apple.com/documentation/avfoundation/avplayer/1386726-play?language=objc
https://developer.apple.com/documentation/avfoundation/avplayer/3929373-defaultrate?language=objc
The second link contains a note about not starting playback by setting the rate to 1.0. I assume this is because of the introduction of
defaultRate
(which can be different than 1.0) and not becauseplay
may do something more than just settingrate
as that wording is explicit about setting rate to 1.0, it says nothing about any other value.This is also why flutter/plugins#4331 did not work well. It was setting
rate
to 1.0 (throughplay
) then immediately to the value set bysetPlaybackSpeed
. One of them or both caused change toplaybackLikelyToKeepUp
which triggeredobserveValueForKeyPath
withplaybackLikelyToKeepUpContext
which in turn called againupdatePlayingState
where wasrate
again changed first to 1.0 then to another value and so on. In this PR the rate is changed only once and then to the same value, seems whenrate
is assigned but not really changed it does not trigger anything.In issues below
seekTo
can triggerplaybackLikelyToKeepUp
change which will callupdatePlayingState
and resetrate
to 1.0 throughplay
. When the speed is set in dart before initialization then the dart side will set it right after callingplay
but even some time after initialization there is still a flood of events callingupdatePlayingState
and it is likely that some of them will call it aftersetPlaybackSpeed
. Actually even whensetPlaybackSpeed
was not called on dart side it (dart side) will always change speed after play to 1.0 so it ignores this newdefaultRate
feature.Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style, or this PR is exempt from CHANGELOG changes.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.